package main

import (
	"fmt"
	"github.com/spf13/cobra"
	"os"
	"wskyygyso/api/app/cmd"
	make2 "wskyygyso/api/app/cmd/make"
	"wskyygyso/api/bootstrap"
	mconfig "wskyygyso/api/config"
	"wskyygyso/api/pkg/config"
	"wskyygyso/api/pkg/console"
)

func init() {
	mconfig.Initialize()
}

func main() {
	var rootCmd = &cobra.Command{
		Use:   config.Get("app.name"),
		Short: "test project",
		Long:  `Default will run "serve" command, you can use "-h" flag to see all subcommands`,
		PersistentPreRun: func(cobraCmd *cobra.Command, args []string) {
			config.InitConfig(cmd.Env)
			//初始化日志
			bootstrap.SetUpLogger()
			//初始化数据库
			bootstrap.SetUpDb()
			//初始化redis
			bootstrap.SetUpRedis()
			// 初始化缓存
			bootstrap.SetUpCache()
		},
	}

	rootCmd.AddCommand(
		cmd.CmdServe,
		cmd.CmdKey,
		cmd.CmdPlay,
		make2.CmdMake,
		cmd.CmdDBSeed,
		cmd.CmdCache,
		cmd.CmdCron,
	)
	cmd.RegisterDefaultCmd(rootCmd, cmd.CmdServe)
	cmd.RegisterGlobalFlags(rootCmd)
	if err := rootCmd.Execute(); err != nil {
		console.Exit(fmt.Sprintf("Failed to run app with %v: %s", os.Args, err.Error()))
	}
}
